package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.HUAWEI.AtLockedItemInfoTi;
import com.ruoyi.system.domain.base.DataIsolationLockMom;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IDataIsolationLockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隔离锁定数据Controller
 *
 * @author ruoyi
 * @date 2023-03-16
 */
@Api(tags = "隔离锁定接口api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/lock" )
public class DataIsolationLockController extends BaseController {

    private final IDataIsolationLockService iDataIsolationLockService;

    /**
     * 查询隔离锁定数据列表MOM
     */
    @ApiOperation(value = "查询隔离锁定数据列表MOM")
    @GetMapping("/list")
    public TableDataInfo list(DataIsolationLockMom dataIsolationLockMom)
    {
        startPage();
        LambdaQueryWrapper<DataIsolationLockMom> lqw = new LambdaQueryWrapper<DataIsolationLockMom>();

        if (StringUtils.isNotBlank(dataIsolationLockMom.getBarcode())){
            lqw.eq(DataIsolationLockMom::getBarcode , dataIsolationLockMom.getBarcode());
        }
        if (StringUtils.isNotBlank(dataIsolationLockMom.getPsn())){
            lqw.eq(DataIsolationLockMom::getPsn , dataIsolationLockMom.getPsn());
        }
        lqw.eq(DataIsolationLockMom::getHaweiAndMom,0);
        List<DataIsolationLockMom> list = iDataIsolationLockService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 查询隔离锁定数据列表华为
     */
    @ApiOperation(value = "查询隔离锁定数据列表华为")
    @GetMapping("/listHuawei")
    public TableDataInfo listHuawei(AtLockedItemInfoTi atLockedItemInfoTi)
    {
        startPage();
        List<AtLockedItemInfoTi> list = iDataIsolationLockService.listHuawei(atLockedItemInfoTi);
        return getDataTable(list);
    }

    /**
     * 导出隔离锁定数据列表
     */
    @Log(title = "隔离锁定数据" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(DataIsolationLockMom dataIsolationLockMom) {
        LambdaQueryWrapper<DataIsolationLockMom> lqw = new LambdaQueryWrapper<DataIsolationLockMom>(dataIsolationLockMom);
        List<DataIsolationLockMom> list = iDataIsolationLockService.list(lqw);
        ExcelUtil<DataIsolationLockMom> util = new ExcelUtil<DataIsolationLockMom>(DataIsolationLockMom. class);
        return util.exportExcel(list, "lock" );
    }

    /**
     * 获取隔离锁定数据详细信息
     */
    @ApiOperation(value = "获取隔离锁定数据详细信息")
    @GetMapping(value = "/{pkid}" )
    public AjaxResult getInfo(@PathVariable("pkid" ) Long pkid) {
        return AjaxResult.success(iDataIsolationLockService.getById(pkid));
    }

    /**
     * 新增隔离锁定数据
     */
    @ApiOperation(value = "新增隔离锁定数据")
    @Log(title = "隔离锁定数据" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataIsolationLockMom dataIsolationLockMom) {
        dataIsolationLockMom.setCreatedBy(SecurityUtils.getUsername());
        dataIsolationLockMom.setCreatedDate(new Date());
        dataIsolationLockMom.setTransId(String.valueOf(new Date().getTime()));
        return toAjax(iDataIsolationLockService.save(dataIsolationLockMom) ? 1 : 0);
    }

    /**
     * 修改隔离锁定数据
     */
    @ApiOperation(value = "修改隔离锁定数据")
    @Log(title = "隔离锁定数据" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataIsolationLockMom dataIsolationLockMom) {
        dataIsolationLockMom.setUpdatedBy(SecurityUtils.getUsername());
        dataIsolationLockMom.setUpdatedDate(new Date());
        return toAjax(iDataIsolationLockService.updateById(dataIsolationLockMom) ? 1 : 0);
    }

    /**
     * 删除隔离锁定数据
     */
    @ApiOperation(value = "删除隔离锁定数据")
    @Log(title = "隔离锁定数据" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{pkids}" )
    public AjaxResult remove(@PathVariable Long[] pkids) {
        return toAjax(iDataIsolationLockService.removeByIds(Arrays.asList(pkids)) ? 1 : 0);
    }




}
